<template>
	<view>
		<view class="list flex" v-for="(item,index) in list">
			<view class="list-top">
				<text>{{item.namewenid}}</text>
				<view>ID:{{id}}</view>
			</view>
			<view class="list-bottom" @tap="save(item.id)">恢复</view>
		</view>
	</view>
</template>

<script>
	import api from "@/common/api.js";
	import {
		baseURL
	} from "@/common/http.js";
	export default {
		data() {
			return {
				list: [],
				id: '',
				ip: '',
				pageNo: 1
			};
		},
		methods: {
			save(id) {
				this.list.forEach((item, index) => {
					if (item.id == id) {
						api.look({
							api: 'updatec',
							del: 1,
							table: 3,
							id: id
						}).then(res => {
							if (res.code == 200) {
								this.list.splice(index, 1)
							}
						}).catch(err => {
							console.log(err)
						})
					}
				})
			},
			getList(data) {
				api.look(data).then(res => {
					if (res.code == 200) {
						this.list = this.list.concat(res.date)
					} else if(res.code == 404) {
						uni.showToast({
							title: '没有更多了',
							icon: 'none',
							duration: 2000
						})
						return this.list
					}
				}).catch(err => {
					console.log(err)
				})
			}
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad() {
			this.id = uni.getStorageSync('message')[0].id
			this.ip = uni.getStorageSync('message')[0].ip
			this.guang = uni.getStorageSync('message')[0].guang // 管理员2 普通用户是1
			let data = {}
			if(this.guang == 2) {
				data = {
					api: 'wenpeg1',
					table: 3,
					page: this.pageNo,
					order: 'deldate desc',
					del: 2
				}
			} else {
				data = {
					api: 'wenpeg1',
					nameid: this.id,
					table: 3,
					page: this.pageNo,
					order: 'deldate desc',
					del: 2
				}
			}
			this.getList(data)
		},
		onReachBottom() {
			this.pageNo++ 
			this.getList({
				api: 'wenpeg1',
				nameid: uni.getStorageSync('message')[0].id,
				table: 3,
				page: this.pageNo,
				order: 'deldate desc',
				del: 2
			})
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F0F0F0;
		font-family: PingFang SC;
	}

	.list {
		width: 690rpx;
		height: 160rpx;
		margin: 20rpx auto;
		background-color: #fff;
		border-radius: 5rpx;
		justify-content: space-between;

		.list-top {
			padding: 30rpx 20rpx;
			box-sizing: border-box;

			text {
				font-size: 36rpx;
				font-weight: 500;
				color: #333;
				font-weight: 500;
			}
		}

		.list-bottom {
			width: 80rpx;
			height: 40rpx;
			line-height: 40rpx;
			color: #309AC7;
			border: 1px solid #209FFC;
			border-radius: 20rpx;
			text-align: center;
			font-size: 20rpx;
			margin-right: 20rpx;
		}
	}
</style>
